<%@page import="java.util.Date" %>
<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="../include/tag.jsp" %>
<!DOCTYPE html>
<html lang="zh">
<head>
    <title>众筹项目管理</title>
    <link rel="stylesheet" href="${ctx}/css/common/list.css">
    <link rel="stylesheet" href="${ctx}/css/common/table.css">
    <%@include file="../include/commonFile.jsp" %>
</head><body>
<!--头部-->
<%@include file="../include/header.jsp" %>
<div class="index-outside">
    <%@include file="../include/sidebar.jsp" %>
    <!--内容-->
    <section>
        <div class="section-main">
            <div class="layui-tab-item layui-show">
                <div class="layui-tab layui-tab-brief" lay-filter="type">
                    <ul class="layui-tab-title" id="zc_tab">
                        <li <c:if test="${activity.isCopartner == 2}">class="layui-this"</c:if>>合作商发布</li>
                        <li <c:if test="${activity.isCopartner == 1}">class="layui-this"</c:if>>合伙人参与</li>
                    </ul>
                    <div class="layui-tab-content">
                        <form class="layui-form" action="${ctx}/activity/zcActivity/zcActivityCopartnerList.do" id="myForm"
                              method="post">
                            <input type="hidden" name="pageNo" id="pageNo"/>
                            <input type="hidden" name="eventId" value="${activity.eventId}"/>
                            <div class="f-search-bar">
                                <div class="search-container">
                                    <ul class="search-form-content">
                                        <li class="form-item-inline"><label class="search-form-lable">项目名称</label>
                                            <div class="layui-input-inline">
                                                <input type="text" name="title" autocomplete="off" class="layui-input"
                                                       value="${activity.title}" placeholder="请输入查询项目名称">
                                            </div>
                                        </li>
                                        <li class="form-item-inline"><label class="search-form-lable">主题名称</label>
                                            <div class="layui-input-inline">
                                                <input type="text" name="eventName" autocomplete="off" class="layui-input" value="${activity.eventName}" placeholder="请输入众筹主题名称">
                                            </div>
                                        </li>
                                        <li class="form-item-inline"><label class="search-form-lable">项目状态</label>
                                            <div class="layui-input-inline">
                                                <select name="timeStatus">
                                                    <option value="">全部</option>
                                                    <option value="0" ${input.timeStatus == 0 ? 'selected' : ''}>进行中</option>
                                                    <option value="1" ${input.timeStatus == 1 ? 'selected' : ''}>已截止</option>
                                                </select>
                                            </div>
                                        </li>
                                    </ul>
                                    <ul class="search-form-content">
                                        <li class="form-item-inline"><label class="search-form-lable">合&nbsp;作&nbsp;&nbsp;商</label>
                                            <div class="layui-input-inline">
                                                <input type="text" name="memberName" autocomplete="off"
                                                       class="layui-input" value="${input.memberName}"
                                                       placeholder="请输入合作商名称">
                                            </div>
                                        </li>
                                        <li class="form-item-inline"><label class="search-form-lable">合&nbsp;伙&nbsp;&nbsp;人</label>
                                            <div class="layui-input-inline">
                                                <input type="text" name="copartnerName" autocomplete="off"
                                                       class="layui-input" value="${activity.copartnerName}"
                                                       placeholder="请输入合伙人名称">
                                            </div>
                                        </li>
                                        <li class="form-item-inline" style="width: 262.44px">

                                        </li>
                                    </ul>
                                    <ul class="search-form-content">
                                        <li class="form-item"><label class="search-form-lable">参与时间</label>
                                            <div class="check-btn-inner" id="timeType">
                                                <a id="all" href="javascript:void(0);"
                                                   onclick="setTimeType($(this),0,'#myForm')" ${empty input.timeType || input.timeType == 0 ? 'class="active"' : ''}>全部</a>
                                                <a href="javascript:void(0);"
                                                   onclick="setTimeType($(this),1,'#myForm')" ${input.timeType == 1 ? 'class="active"' : ''}>今天</a>
                                                <a href="javascript:void(0);"
                                                   onclick="setTimeType($(this),2,'#myForm')" ${input.timeType == 2 ? 'class="active"' : ''}>本周内</a>
                                                <a href="javascript:void(0);"
                                                   onclick="setTimeType($(this),3,'#myForm')" ${input.timeType == 3 ? 'class="active"' : ''}>本月内</a>
                                                <input type="hidden" name="timeType" value="${input.timeType}"/>
                                            </div>
                                            <div class="layui-inline">
                                                <div class="layui-input-inline">
                                                    <input class="layui-input" type="text" name="createStart"
                                                           value="${input.createStart}" placeholder="开始日">
                                                </div>
                                                -
                                                <div class="layui-input-inline">
                                                    <input class="layui-input" type="text" name="createEnd"
                                                           value="${input.createEnd}" placeholder="截止日">
                                                </div>
                                            </div>
                                        </li>
                                        <li class="form-item-inline">
                                            <div class="sub-btns">
                                                <a class="layui-btn layui-btn-danger"
                                                   href="javascript:submitFunction('#myForm')">查询</a>
                                                <a class="layui-btn layui-btn-normal"
                                                   href="javascript:resetFunction('#myForm')">重置</a>
                                            </div>
                                        </li>
                                    </ul>
                                </div>
                            </div>
                        </form>
                        <div class="c-time-list-content">
                            <ul id="view">
                                <c:if test="${page.totalCount == 0}">
                                    <div class="f16 tc mt15">还没有数据，请点击右上角的“发布众筹项目”</div>
                                </c:if>
                                <c:forEach var="activity" items="${activities}">
                                    <li>
                                        <div class="detail-content">
                                            <a href="${ctx}/activity/zcActivity/zcActivityCopartnerDetail.do?actId=${activity.id}"
                                               target="_self" class="act-logo common-img"
                                            >
                                                <img src="<c:if test="${activity.pic != null}">${activity.pic}?imageMogr2/auto-orient/crop/200x150</c:if>" alt="" onerror="txz.errImg(this)" onload="txz.imgLoad(this)">
                                            </a>
                                            <div class="detail">
                                                <div class="act-title">
                                                    <c:choose>
                                                        <c:when test="${activity.checkStatus == 0}">
                                                            <span class="status f20 red">审核中</span>
                                                        </c:when>
                                                        <c:when test="${activity.checkStatus == 1}">
                                                            <c:set var="nowDate" value="<%=new Date()%>"></c:set>
                                                            <c:if test="${activity.endTime > nowDate}">
                                                                <span class="status f20 red">进行中</span>
                                                            </c:if>
                                                            <c:if test="${activity.endTime < nowDate}">
                                                                <span class="status f18 dark">已截止</span>
                                                            </c:if>
                                                        </c:when>
                                                        <c:when test="${activity.checkStatus == 2}">
                                                            <span class="status f18 dark">已拒绝</span>
                                                        </c:when>
                                                    </c:choose>
                                                    <a title="${activity.title}"
                                                       href="${ctx}/activity/zcActivity/zcActivityCopartnerDetail.do?actId=${activity.id}"
                                                       target="_self" class="title f18 ell db">${activity.title}</a>
                                                </div>
                                                <div>
                                                    <p class="act-price">
                                                        <span style="margin-right: 10px;">截止时间：<fmt:formatDate value="${activity.endTime}" pattern="yyyy-MM-dd HH:mm"/></span>
                                                        <span style="margin-right: 10px;">报名费用：<b class="active-red">${activity.price}</b>元/位</span>
                                                        <span>报名人数：<b class="active-red">${activity.joinNum}</b>人</span>
                                                    </p>
                                                    <p class="act-price">
                                                        <span style="margin-right: 10px;">合作商：<b class="active-red">${activity.member}</b></span>
                                                        <span style="margin-right: 10px;">合伙人：<b class="active-red">${activity.copartnerName}</b></span>
                                                        <span>主题名称：<b class="active-red">${activity.eventName}</b></span>
                                                    </p>
                                                    <p class="start-time">活动地点：${activity.place}</p>
                                                    <p class="act-price">
                                                        参与时间：
                                                        <fmt:formatDate value="${activity.joinTime}" pattern="yyyy-MM-dd HH:mm"/>
                                                    </p>
                                                </div>
                                                <div class="opts-btns tb-opts" style="width:475px">
                                                    <div class="comm-opts">
                                                        <c:if test="${activity.checkStatus == 1}">
                                                            <a class="qr-btn"
                                                               href="javascript:txz.openQrDialog({
                                                               title:'扫码二维码可预览分享',
                                                               detailList:[
                                                                   {
                                                                   title:'报名二维码',
                                                                   url:'${activity.bmQrCodeUrl }'
                                                                   },
                                                                   {
                                                                   title:'联合发起二维码',
                                                                   url:'${activity.qrCodeUrl }'
                                                                   }
                                                               ]
                                                               })"><i
                                                                    class="iconfont icon-qrcode btn-icon"></i> 二维码</a>
                                                        </c:if>
                                                        <a href="${ctx}/activity/activity/zcCrowdfundList.do?id=${activity.id}">
                                                            <i class="iconfont icon-searchlist btn-icon"></i>
                                                            数据查看
                                                        </a>
                                                        <a target="_blank"
                                                           href="${ctx}/crowdfund/analyze/list.do?targetId=${activity.id}">
                                                            <i class="iconfont icon-news btn-icon"></i>
                                                            数据分析
                                                        </a>
                                                        <a href="${ctx}/notify/template/list.do?targetId=${activity.id}">
                                                            <i class="iconfont icon-mail btn-icon"></i>
                                                            短信推送
                                                        </a>
                                                        <a href="${ctx}/crowdfund/target/copyView.do?id=${activity.id}"> <i class="iconfont icon-copy btn-icon"></i> 复制众筹项目</a>
                                                        <a href="${ctx}/activity/activity/zcActivityForm.do?id=${activity.id}">
                                                            <i class="iconfont icon-edit btn-icon"></i> 编辑</a>
                                                        <a href="javascript:txz.deleteObject('确定要删除众筹项目吗？','${ctx}/activity/activity/deleteLogic.do?id=${activity.id}','该众筹项目已有人报名，不能删除')">
                                                            <i class="iconfont icon-delete btn-icon"></i> 删除
                                                        </a>
                                                        <a href="javascript:txz.giftUtil.openSetGift('${activity.id}', '${activity.title}', 'ZC_ACTIVITY')">配置礼包</a>
                                                        <c:if test="${activity.checkStatus == 0}">
                                                            <a class="green"
                                                               href="javascript:verify('确认要通过吗？','1','${activity.id}')">
                                                                <i class="iconfont icon-check btn-icon"></i>通过</a>
                                                            <a class="red"
                                                               href="javascript:verify('确认要拒绝吗？','2','${activity.id}')">
                                                                <i class="iconfont icon-close btn-icon"></i>拒绝</a>
                                                        </c:if>
                                                    </div>
                                                </div>
                                            </div>
                                        </div>
                                    </li>
                                </c:forEach>
                            </ul>
                            <div id="page_content" class="page-container"></div>
                        </div>
                    </div>
                </div>
            </div>
        </div><!--底部-->
        <%@include file="../include/footer.jsp" %>
    </section>
    <%@include file="../gift/giftInclude.jsp"%>
</div>

<script type="text/javascript" src="${ctx}/script/common/list.js"></script>
<script type="text/javascript" src="${ctx}/script/common/table_option.js"></script>
<script type="text/javascript">
    txz.initHeader({
        nav:[{
            name: '众筹项目管理',
            curr: true
        }],
        info:'<span class="f12">共<b>${page.totalCount}</b>条记录',
        btns:[{
            name: '发布众筹项目',
            icon: 'add',
            href: '${ctx}/activity/activity/zcActivityForm.do'
        }]
    });
    <%--showActive('${input.createStart}', '${input.createEnd}', '#timeType');--%>
    $(function () {
        //加载分页
        loadPageNew({elem: 'page_content', totalCount: '${page.totalCount}', limit: '${page.limit}', page: '${page.page}'});

        layui.use(['laytpl', 'laypage', 'element', 'laydate'], function () {
            var laytpl = layui.laytpl, laypage = layui.laypage, laydate = layui.laydate, element = layui.element;


            // 查询开始日期
            var start = {
                elem: 'input[name=e_start]'
            };

            var end = {
                elem: 'input[name=e_end]'
            };
            laydate.render(start);
            laydate.render(end);

            // 查询发布日期
            var start = {
                elem: 'input[name=createStart]'
            };

            var end = {
                elem: 'input[name=createEnd]'
            };
            laydate.render(start);
            laydate.render(end);

            element.on('tab(type)', function (data) {
                var eventId = '';
                var val = $('input[name=eventId]').val();
                if (val) {
                    eventId = '?eventId=' + val;
                }
                if (data.index == 0) {
                    location.href = "${ctx}/activity/activity/zcActivityList.do" + eventId;
                }
                else if (data.index == 1) {
                    location.href = "${ctx}/activity/zcActivity/zcActivityCopartnerList.do" + eventId;
                }
            });
        });

    })

    // 审核
    function verify(content, checkStatus, actId) {
        layer.confirm(content, {
            icon: 3,
            title: '系统提示'
        }, function (index) {
            layer.close(index);
            $.post("${ctx}/activity/activity/verify.do", {
                checkStatus: checkStatus,
                actId: actId
            }, function (data) {
                if (data.success == true) {
                    util.layerAlertSuccess("审核成功", function () {
                        window.location.reload();
                    })
                }
            })
        });
    }

    function copy(id) {
        var confirmIndex = layer.confirm('确认复制众筹项目所有内容吗?',{title:'系统提示'},function(index){
            layer.close(confirmIndex);
            //loading层
            var loadIndex = layer.load(1, {
                shade: [0.1,'#fff'] //0.1透明度的白色背景
            });
            $.post("${ctx}/crowdfund/target/copy.do", {
                id: id
            }, function (data) {
                top.layer.close(loadIndex);
                if (data.success == true) {
                    util.layerAlertSuccess("复制成功", function () {
                        window.location.reload();
                    })
                } else {
                    util.layerAlertError(data.description)
                }
            });
        });
    }

    function createCircle(actId) {
        var content = "确定要生成吗？请选择生成<br/><label for='all1' class='mr10'><input type='radio' id='all1' name='type' value='2' checked='checked' >全部报名人员</label>" +
            "<label for='success'><input type='radio' id='success' name='type' value='1' >已成功报名人员</label>";
// 		content = "确定要生成吗？";
        layer.confirm(content, {
            icon: 3,
            title: '系统提示'
        }, function (index) {
            var type = $("[name=type]:checked").val() || '2';
            layer.close(index);
            //loading层
            var loadIndex = layer.load(1, {
                shade: [0.1, '#fff'] //0.1透明度的白色背景
            });
            $.post("${ctx}/activity/activity/createCircle.do", {
                actId: actId,
                type: type
            }, function (data) {
                layer.close(loadIndex);
                setTimeout(function () {
                    if (data.success == true) {
                        util.layerMsgSuccess("生成成功")
                    } else {
                        util.layerMsgError("生成失败")
                    }
                });
            })
        });
    }

    function send(id) {
        var content = "请选择类型<br/><label for='all1' class='mr10'><input type='radio' id='all1' name='type' value='0' checked='checked' >所有众筹</label>" +
            "<label for='success' class='mr10'><input type='radio' id='success' name='type' value='1' >众筹成功</label>" +
            "<label for='success'><input type='radio' id='success' name='type' value='2' >众筹中</label>";
        layer.confirm(content, {
            icon: 3,
            title: '系统提示'
        }, function (index) {
            var type = $("[name=type]:checked").val() || '0';
            layer.close(index);
            $.post("${ctx}/crowdfund/event/createCircle.do", {
                id: id,
                type: type
            }, function (data) {
                if (data.success == true) {
                    util.layerMsgSuccess("生成成功")
                } else {
                    util.layerMsgError("生成失败")
                }
            })
        });
    }
</script>
</body>
</html>